<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="stuName">
        <el-input v-model="queryParams.stuName" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="班级" prop="className">
        <el-input v-model="queryParams.className" placeholder="请输入班级" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="辅导员" prop="teacher">
        <el-input v-model="queryParams.teacher" placeholder="请输入辅导员" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:records:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:records:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:records:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:records:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="stuName" />
      <el-table-column label="班级" align="center" prop="className" />
      <!-- <el-table-column label="宿舍长" align="center" prop="dormitoryHead">
        <template slot-scope="scope">{{ scope.row.dormitoryHead == '是' ? '是' : '否' }}</template>
      </el-table-column> -->
      <el-table-column label="学号" align="center" prop="stuNo" />
      <!-- <el-table-column label="宿舍号1" align="center" prop="roomNo1" /> -->
      <!-- <el-table-column label="标准人数1" align="center" prop="standardCapacity" /> -->
      <!-- <el-table-column label="实住人数1" align="center" prop="actualOccupancy" /> -->
      <!-- <el-table-column label="住宿时间1" align="center" prop="accommodationDuration1" /> -->
      <!-- <el-table-column label="折合月数" align="center" prop="equivalentMonths1" /> -->
      <!-- <el-table-column label="收费标准" align="center" prop="chargeStandard1" /> -->
      <!-- <el-table-column label="应收费用1" align="center" prop="amountDue1" /> -->
      <!-- <el-table-column label="宿舍号2" align="center" prop="roomNo2" /> -->
      <!-- <el-table-column label="标准数" align="center" prop="standardCapacity2" /> -->
      <!-- <el-table-column label="宿舍实住人数" align="center" prop="actualOccupancy2" /> -->
      <!-- <el-table-column label="住宿时间" align="center" prop="accommodationDuration2" /> -->
      <!-- <el-table-column label="折合月数" align="center" prop="equivalentMonths2" /> -->
      <!-- <el-table-column label="收费标准" align="center" prop="chargeStandard2" /> -->
      <!-- <el-table-column label="应收费用" align="center" prop="amountDue2" /> -->
      <el-table-column label="年住宿费用" align="center" prop="annualAccommodationFee" />
      <!-- <el-table-column label="银行账号" align="center" prop="bankAccount" /> -->
      <!-- <el-table-column label="电话" align="center" prop="phone" /> -->
      <!-- <el-table-column label="辅导员" align="center" prop="teacher" /> -->
      <!-- <el-table-column label="辅导员电话" align="center" prop="teacherPhone" /> -->
      <!-- <el-table-column label="备注1" align="center" prop="remark1" /> -->
      <!-- <el-table-column label="备注2" align="center" prop="remark2" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="lookTotal(scope.row)">查看明细</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:records:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:records:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改宿舍费用对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="stuName">
          <el-input v-model="form.stuName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="班级" prop="className">
          <el-input v-model="form.className" placeholder="请输入班级" />
        </el-form-item>
        <el-form-item label="宿舍长" prop="dormitoryHead">
          <el-input v-model="form.dormitoryHead" placeholder="请输入宿舍长" />
        </el-form-item>
        <el-form-item label="学号" prop="stuNo">
          <el-input v-model="form.stuNo" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="宿舍号1" prop="roomNo1">
          <el-input v-model="form.roomNo1" placeholder="请输入宿舍号1" />
        </el-form-item>
        <el-form-item label="标准人数1" prop="standardCapacity">
          <el-input v-model="form.standardCapacity" placeholder="请输入标准人数1" />
        </el-form-item>
        <el-form-item label="实住人数1" prop="actualOccupancy">
          <el-input v-model="form.actualOccupancy" placeholder="请输入实住人数1" />
        </el-form-item>
        <el-form-item label="住宿时间1" prop="accommodationDuration1">
          <el-input v-model="form.accommodationDuration1" placeholder="请输入住宿时间1" />
        </el-form-item>
        <el-form-item label="折合月数" prop="equivalentMonths1">
          <el-input v-model="form.equivalentMonths1" placeholder="请输入折合月数" />
        </el-form-item>
        <el-form-item label="收费标准" prop="chargeStandard1">
          <el-input v-model="form.chargeStandard1" placeholder="请输入收费标准" />
        </el-form-item>
        <el-form-item label="应收费用1" prop="amountDue1">
          <el-input v-model="form.amountDue1" placeholder="请输入应收费用1" />
        </el-form-item>
        <el-form-item label="宿舍号2" prop="roomNo2">
          <el-input v-model="form.roomNo2" placeholder="请输入宿舍号2" />
        </el-form-item>
        <el-form-item label="标准数" prop="standardCapacity2">
          <el-input v-model="form.standardCapacity2" placeholder="请输入标准数" />
        </el-form-item>
        <el-form-item label="宿舍实住人数" prop="actualOccupancy2">
          <el-input v-model="form.actualOccupancy2" placeholder="请输入宿舍实住人数" />
        </el-form-item>
        <el-form-item label="住宿时间" prop="accommodationDuration2">
          <el-input v-model="form.accommodationDuration2" placeholder="请输入住宿时间" />
        </el-form-item>
        <el-form-item label="折合月数" prop="equivalentMonths2">
          <el-input v-model="form.equivalentMonths2" placeholder="请输入折合月数" />
        </el-form-item>
        <el-form-item label="收费标准" prop="chargeStandard2">
          <el-input v-model="form.chargeStandard2" placeholder="请输入收费标准" />
        </el-form-item>
        <el-form-item label="应收费用" prop="amountDue2">
          <el-input v-model="form.amountDue2" placeholder="请输入应收费用" />
        </el-form-item>
        <el-form-item label="年住宿费用" prop="annualAccommodationFee">
          <el-input v-model="form.annualAccommodationFee" placeholder="请输入年住宿费用" />
        </el-form-item>
        <el-form-item label="银行账号" prop="bankAccount">
          <el-input v-model="form.bankAccount" placeholder="请输入银行账号" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="辅导员" prop="teacher">
          <el-input v-model="form.teacher" placeholder="请输入辅导员" />
        </el-form-item>
        <el-form-item label="辅导员电话" prop="teacherPhone">
          <el-input v-model="form.teacherPhone" placeholder="请输入辅导员电话" />
        </el-form-item>
        <el-form-item label="备注1" prop="remark1">
          <el-input v-model="form.remark1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注2" prop="remark2">
          <el-input v-model="form.remark2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="查看明细" :visible.sync="totalV" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item style="margin-bottom: 0;" label="姓名" prop="stuName">
          <el-input v-model="form.stuName" readonly />
        </el-form-item>
        <el-form-item style="margin-bottom: 0;" label="班级" prop="className">
          <el-input v-model="form.className" readonly />
        </el-form-item>
        <el-form-item style="margin-bottom: 0;" label="学号" prop="stuNo">
          <el-input v-model="form.stuNo" readonly />
        </el-form-item>
        <el-form-item style="margin-bottom: 0;" label="年住宿费用" prop="annualAccommodationFee">
          <el-input v-model="form.annualAccommodationFee" readonly />
        </el-form-item>
        <el-form-item style="margin-bottom: 0;" label="银行账号" prop="bankAccount">
          <el-input v-model="form.bankAccount" readonly />
        </el-form-item>
        <el-form-item style="margin-bottom: 0;" label="电话" prop="phone">
          <el-input v-model="form.phone" readonly />
        </el-form-item>
        <el-table :data="total_list">
          <el-table-column label="住宿日期" align="center" prop="accommodationDuration" />
          <el-table-column label="折合月数" align="center" prop="equivalentMonths" />
          <el-table-column label="应收费用" align="center" prop="amountDue" />
        </el-table>
      </el-form>
    </el-dialog>


  </div>
</template>

<script>
import { listRecords, getRecords, delRecords, addRecords, updateRecords } from "@/api/dormitory/dormitoryRecords";

export default {
  name: "Records",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 宿舍费用表格数据
      recordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuName: null,
        className: null,
        dormitoryHead: null,
        stuNo: null,
        roomNo1: null,
        standardCapacity: null,
        actualOccupancy: null,
        accommodationDuration1: null,
        equivalentMonths1: null,
        chargeStandard1: null,
        amountDue1: null,
        roomNo2: null,
        standardCapacity2: null,
        actualOccupancy2: null,
        accommodationDuration2: null,
        equivalentMonths2: null,
        chargeStandard2: null,
        amountDue2: null,
        annualAccommodationFee: null,
        bankAccount: null,
        phone: null,
        teacher: null,
        teacherPhone: null,
        remark1: null,
        remark2: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        stuName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        className: [
          { required: true, message: "班级不能为空", trigger: "blur" }
        ],
        stuNo: [
          { required: true, message: "学号不能为空", trigger: "blur" }
        ],
      },

      totalV: false,
      total_list:[]
    };
  },
  created() {
    this.getList();
  },
  methods: {

    lookTotal(row) {
      this.form = { ...row };
      this.totalV = true;
      let temp1 = {
        "accommodationDuration":row.accommodationDuration1,
        "amountDue":row.amountDue1,
        "equivalentMonths":row.equivalentMonths1

      }
      let temp2 = {
        "accommodationDuration":row.accommodationDuration2,
        "amountDue":row.amountDue2,
        "equivalentMonths":row.equivalentMonths2

      }

      this.total_list.push(temp1);
      this.total_list.push(temp2);
    },

    /** 查询宿舍费用列表 */
    getList() {
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        this.recordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stuName: null,
        className: null,
        dormitoryHead: null,
        stuNo: null,
        roomNo1: null,
        standardCapacity: null,
        actualOccupancy: null,
        accommodationDuration1: null,
        equivalentMonths1: null,
        chargeStandard1: null,
        amountDue1: null,
        roomNo2: null,
        standardCapacity2: null,
        actualOccupancy2: null,
        accommodationDuration2: null,
        equivalentMonths2: null,
        chargeStandard2: null,
        amountDue2: null,
        annualAccommodationFee: null,
        bankAccount: null,
        phone: null,
        teacher: null,
        teacherPhone: null,
        remark1: null,
        remark2: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加宿舍费用";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecords(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改宿舍费用";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecords(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecords(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除宿舍费用编号为"' + ids + '"的数据项？').then(function () {
        return delRecords(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/dormitory/records/export', {
        ...this.queryParams
      }, `records_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
